package leetcode;

public class RansomNote {
	
	public static void main(String[] args) {
		RansomNote note = new RansomNote();
		System.out.println(note.canConstruct("aa", "aab"));
	}

	public boolean canConstruct(String ransomNote, String magazine) {
		if (ransomNote == null) {
			return true;
		}
		if (magazine == null) {
			return ransomNote == null;
		}
		if (ransomNote.length() > magazine.length()) {
			return false;
		}
		char[] ransomWords = ransomNote.toCharArray();
		char[] magazineWords = magazine.toCharArray();
		int[] ransomCount = new int[26];
		int[] magazineCount = new int[26];
		for (int i = 0; i < ransomWords.length; i++) {
			ransomCount[ransomWords[i] - 'a']++;
		}
		for (int i = 0; i < magazineWords.length; i++) {
			magazineCount[magazineWords[i] - 'a']++;
		}
		for (int i = 0; i < 26; i++) {
			System.out.println(ransomCount[i] + "  " + magazineCount[i]);
			if (ransomCount[i] > magazineCount[i]) {
				return false;
			}
		}
		return true;
	}
}
